package org.ruiyichen.guizhou.agr.ui.mineview.dropdownmenu;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

public abstract class BaseDropdownAdapter<T> extends BaseAdapter implements DropdownAdapter {

    protected Context context;

    protected List<T> list;

    public BaseDropdownAdapter(Context context, List<T> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public T getItem(int position) {
        return null == list ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return onCreateView(convertView, parent, list.get(position), position);
    }

    /**
     * 创建界面并binding数据
     *
     * @param convertView
     * @param parent
     * @param data
     * @return
     */
    public abstract View onCreateView(View convertView, ViewGroup parent, T data, int position);

    /**
     * 选择选项
     *
     * @param position
     */
    public abstract void selectItem(int position);
}
